#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include "cmd.h"
#include "parse.h"

void read_line(char *line, int size)
{
	fgets(line,size,stdin);
	line[strlen(line) - 1] = '\0';
}

int main()
{
    while (1) {
	    char line[128];
	    printf("> ");
	    fflush(stdout);
	    read_line(line,sizeof(line));
	    
	    int cmdc = 0;
	    struct cmd cmdv[10];
	    int i;
	    for(i = 0 ; i < 10 ; i++) {
	    	cmdv[i].argc = 0;
		cmdv[i].input = NULL;
		cmdv[i].output = NULL;
	    }

	    cmdc = parse_pipe_cmd(line,cmdv);
	    //printf("%d\n",cmdc);

	    if(cmdc > 1) exec_pipe_cmd(cmdc,cmdv);
	    else if(cmdc == 1) exec_cmd(cmdv + 0);
    }
    return 0;
}
